﻿using System;
using RpcHelper;
using RpcModel;
using SqlExecHelper;
using SqlExecHelper.SetColumn;
using Wedonek.RpcStore.Service.Helper;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class IdentityAppDAL : SqlBasicClass
        {
                public IdentityAppDAL () : base ("IdentityApp", "RpcExtendService")
                {

                }
                public Guid Add (IdentityApp add)
                {
                        add.Id = Tools.NewGuid ();
                        add.CreateTime = DateTime.Now;
                        base.Insert (add);
                        return add.Id;
                }
                internal void SetIsEnable (Guid id, bool isEnable)
                {
                        if (!base.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("IsEnable", System.Data.SqlDbType.Bit){ Value=isEnable}
                        }, "Id", id))
                        {
                                throw new ErrorException ("rpc.route.set.fail");
                        }
                }
                public void Set (Guid id, IdentitySetParam param)
                {
                        if (!base.Update (param, "Id", id))
                        {
                                throw new ErrorException ("rpc.identity.set.fail");
                        }
                }
                public IdentityApp[] Query (IdentityQueryParam query, IBasicPage paging, out long count)
                {
                        paging.InitOrderBy ("Id", true);
                        return base.Query<IdentityApp> (paging.OrderBy, paging.Index, paging.Size, out count, query.ToWhere ());
                }
                public IdentityApp Get (Guid id)
                {
                        return base.GetRow<Guid, IdentityApp> ("Id", id);
                }
                public void Delete (Guid id)
                {
                        if (!base.Drop ("Id", id))
                        {
                                throw new ErrorException ("rpc.identity.drop.fail");
                        }
                }

        }
}
